package com.atguigu.tingshu.account.mapper;

import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {

    @Update("update user_account\n" +
            "set available_amount = available_amount - #{amount}\n" +
            "    ,total_pay_amount=total_pay_amount + #{amount}\n" +
            "    ,total_amount=total_amount - #{amount}\n" +
            "    where user_id =#{userId} and available_amount >= #{amount} and is_deleted=0 ;")
    int cheackAndDeduct(@Param("amount") BigDecimal amount,@Param("userId") Long userId);
}
